package com.minivision.fdiot.mqtt.auth;

import org.apache.commons.lang3.StringUtils;

import io.moquette.spi.impl.subscriptions.Topic;
import io.moquette.spi.security.IAuthorizator;
import lombok.extern.slf4j.Slf4j;

/**
 * MQTT读写权限控制
 * @author hughzhao
 * @2018年3月1日
 */
@Slf4j
public class DeviceAuthorizator implements IAuthorizator {

  public boolean canWrite(Topic topic, String user, String client) {
    log.trace("Auth {}@{} can write to Topic {}", user, client, topic);
    if (StringUtils.isEmpty(user)) {
      return false;
    }

    // TODO 判断topic client user是否匹配
    return true;
  }

  public boolean canRead(Topic topic, String user, String client) {
    log.trace("Auth {}@{} can read from Topic {}", user, client, topic);
    if (StringUtils.isEmpty(user)) {
      return false;
    }

    // TODO 判断topic client user是否匹配
    return true;
  }
  
}
